package com.b.a.b.crossword.domain.impl;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class UrlWordSource extends AbstractSourceWord {
 
	public UrlWordSource(URL wordSourceurl) {
	super();
	setData( readWord(wordSourceurl));
}
	
	public UrlWordSource(String wordSourceurl) throws MalformedURLException {
		this(new URL(wordSourceurl));
	}
	 
	
	private List<String> readWord(URL wordSourceurl) {
		// TODO Auto-generated method stub
		List<String> res=new ArrayList<String>();
		try {
			 BufferedReader rd=new BufferedReader(new InputStreamReader(wordSourceurl.openStream()));
			 String ligne=null;
			 while(null!=(ligne=rd.readLine()))
				 res.add(ligne.trim());
				 rd.close();
				 return res;
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	
}
